/*
 * CategoryClassificationDoubleCheck is a software package that uses 
 * data mining to verify that descriptions of items are classified 
 * into the correct categories.
 * 
 * Copyright (C) 2011  CommuniPatient, LLC
 * 
 * File: ItemSuggestion.java
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *  
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.unitvectory.categoryclassification;

import org.simpleframework.xml.Element;
import org.simpleframework.xml.Root;

/**
 * Represents a category change suggestion for an item.
 * 
 * @author Jared Hatfield
 * 
 */
@Root(name = "suggestion")
public class ItemSuggestion {

    /**
     * The item name.
     */
    @Element(name = "itemname")
    private String itemName;

    /**
     * The item id.
     */
    @Element(name = "itemid")
    private String itemId;

    /**
     * The category name.
     */
    @Element(name = "categoryname")
    private String categoryName;

    /**
     * The category id.
     */
    @Element(name = "categoryid")
    private String categoryId;

    /**
     * The change that will be made.
     */
    @Element(name = "change")
    private Change change;

    /**
     * The confidence of the prediction.
     */
    @Element(name = "confidence")
    private double confidence;

    /**
     * Initializes a new instance of the ItemSuggestion class.
     */
    public ItemSuggestion() {
        this.itemName = "";
        this.itemId = "";
        this.categoryName = "";
        this.categoryId = "";
        this.change = Change.KEEP;
        this.confidence = 0;
    }

    /**
     * Initializes a new instance of the ItemSuggestion class.
     * 
     * @param item
     *            The item.
     * @param category
     *            The category.
     * @param add
     *            The add flag.
     * @param confidence
     *            The confidence.
     */
    public ItemSuggestion(Item item, Category category, boolean add,
            double confidence) {
        this.itemName = item.getName();
        this.itemId = item.getId();
        this.categoryName = category.getName();
        this.categoryId = category.getId();
        if (add) {
            this.change = Change.ADD;
        } else {
            this.change = Change.REMOVE;
        }

        this.confidence = confidence;
    }

    /**
     * Returns the string representation for the ItemSuggestion.
     */
    @Override
    public String toString() {
        double number = Math.round(this.confidence * 10000) / 100.0;
        if (this.change.equals(Change.ADD)) {
            return "Add " + this.itemName + " (" + this.itemId + ") to "
                    + this.categoryName + " (" + this.categoryId
                    + ") with confidence " + number;
        } else {
            return "Remove " + this.itemName + " (" + this.itemId + ") to "
                    + this.categoryName + " (" + this.categoryId
                    + ") with confidence " + number;
        }
    }

    /**
     * The category change.
     * 
     * @author Jared Hatfield
     * 
     */
    private enum Change {

        /**
         * Add the category.
         */
        ADD,

        /**
         * Remove the category.
         */
        REMOVE,

        /**
         * No selection made.
         */
        KEEP
    }
}
